﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;

//享元模式 示例
namespace Flyweight
{

    public class Font
    {
       public string Name;
        public int Size;
        public Color Fcolor;
        public Font Copy()
        {
            Font f = new Font() { Fcolor=this.Fcolor, Name=this.Name, Size= this.Size };
            return f;
        }
    }

    public class CharCtor
    {
        /// <summary>
        /// 用于存储所有的字符的格式
        /// </summary>
        private static Dictionary<string, Font> AllFontDic = new Dictionary<string, Font>();

        private Font f;
        public char c;
        public Font CharFont
        {
            get
            {
                if (f!=null)
                {
                    return f.Copy();
                }
                return null;
            }
            set
            {
                if (!AllFontDic.ContainsKey( value.Name))
                {
                    AllFontDic.Add(value.Name, value);
                }
                this.f = value;
            }
        }
    }

}
